#include "StdAfx.h"
#include "MemoryAllocator.h"
#include "MemoryTrace.h"

VAMPIRE_NAMESPACE_BEGIN

void MemoryAllocator::deallocBytes( void* ptr )
{
	if(NULL == ptr)
	{
		return;
	}

#ifdef USING_MEM_TRACE
	MemoryTrace::getSingletonPtr()->_recordDealloc(ptr);
#endif

	nedalloc::nedfree(ptr);
}

void* MemoryAllocator::allocBytes( size_t count, const char* file, int line, const char* func )
{
	void* ptr = nedalloc::nedmalloc(count);

#ifdef USING_MEM_TRACE
	MemoryTrace::getSingletonPtr()->_recordAlloc(ptr, count, 0, file, line, func);
#endif

	return ptr;
}

void* MemoryAllocator::allocBytes( size_t count )
{
	void* ptr = nedalloc::nedmalloc(count);
	return ptr;
}

void* MemoryAllocator::allocBytesAligned( size_t align, size_t count,const char* file, int line, const char* func )
{
	void* ptr =  align ? nedalloc::nedmemalign(align, count)
		: nedalloc::nedmemalign(SIMD_ALIGNMENT, count);

#ifdef USING_MEM_TRACE
	MemoryTrace::getSingletonPtr()->_recordAlloc(ptr, count, 0, file, line, func);

#endif
	return ptr;
}

void* MemoryAllocator::allocBytesAligned( size_t align, size_t count )
{
	void* ptr =  align ? nedalloc::nedmemalign(align, count)
		: nedalloc::nedmemalign(SIMD_ALIGNMENT, count);

	return ptr;
}

VAMPIRE_NAMESPACE_END
